<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <HomeCategory />
        <!-- banner轮播图 -->
        <HomeBanner />
        <!-- 新鲜好物内容 -->
        <home-panel :title="'新鲜好物'" :subTitle="'新鲜出炉 品质靠谱'">
          <template #right>
            <span><XtxMore to="/" /></span>
          </template>
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in panelList" :key="item.id">
                <!-- 路由跳转链接 -->
                <RouterLink :to="`/goods/${item.id}`">
                  <img :src="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
        <!-- 人气推荐内容 -->
        <home-panel :title="'人气推荐'" :subTitle="'人气推荐 不容错过'">
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in hotList" :key="item.id">
                <RouterLink to="/">
                  <img alt="" v-lazy-img="item.picture" />
                  <p class="name">{{ item.title }}</p>
                  <p class="name">{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
        <!-- 热门品牌内容 -->
        <home-panel :title="'热门品牌'" :subTitle="'国际经典 品质保障'">
          <template #main>
            <ul ref="pannel" class="brand-list">
              <li v-for="item in brandList" :key="item.id">
                <RouterLink to="/">
                  <img alt="" v-lazy-img="item.logo" />
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
      </div>
    </div>
  </div>
</template>

<script>
import HomeCategory from './components/home-category' // 分类
import HomeBanner from './components/home-banner' // 轮播图
import HomePanel from './components/home-panel.vue' // 主体内容
import { findNew, findHot, findBrand } from '@/api/home'

import { ref } from 'vue'
export default {
  name: 'xtx-home-page',
  components: {
    HomeCategory,
    HomeBanner,
    HomePanel
  },
  setup () {
    const panelList = ref([]) // 热门好物
    const hotList = ref([]) // 人气推荐
    const brandList = ref([]) // 热门品牌

    // 获取主体内容
    async function getPanelList () {
      const res = await findNew()
      panelList.value = res.result
    }
    getPanelList()

    // 获取人气推荐
    async function getHotList () {
      const res = await findHot()
      hotList.value = res.result
    }
    getHotList()

    // 获取热门品牌
    async function getBrandLst () {
      const res = await findBrand()
      brandList.value = res.result
    }
    getBrandLst()

    return { panelList, hotList, brandList }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
.brand-list {
  display: flex;
  li {
    flex: 1;
    padding: 10px;
  }
}
</style>
